package com.jzg.jcptadmin.adpter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.data.vo.Table;

import java.util.List;

/**
 * Created by wangyd on 15/12/29.
 * vin码结果查询列表
 */
public class VinListAdapter extends BaseAdapter {


    private LayoutInflater inflater;

    List<Table> vinResultList;

    public VinListAdapter(Context context, List<Table> vinResultList) {
        super();
        this.inflater = LayoutInflater.from(context);
        this.vinResultList = vinResultList;
    }

    @Override
    public int getCount() {

        return vinResultList.size();
    }

    @Override
    public Object getItem(int position) {
        return vinResultList.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.vin_list_item, null);
            holder = new ViewHolder();
            holder.full_name = (TextView) convertView
                    .findViewById(R.id.full_name);
            holder.factory_price = (TextView) convertView
                    .findViewById(R.id.factory_price);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        Table vinResult = vinResultList.get(position);
        holder.full_name.setText(vinResult.getFullName());
        holder.factory_price.setText(vinResult.getNowMsrp() + "万");

        return convertView;
    }

    public void setData(List<Table> data) {
        vinResultList.clear();
        this.vinResultList = data;
    }

    private class ViewHolder {
        TextView full_name;
        TextView factory_price;
    }

}

